using System;
using System.Collections.Generic;
using System.IO;
using Fody;

public class WeaversXmlHistory
{
    static Dictionary<string, DateTime> timeStamps;

    static WeaversXmlHistory()
    {
        timeStamps = new Dictionary<string, DateTime>();
    }

    public BuildLogger Logger;
    public ProjectWeaversFinder ProjectWeaversFinder;
    public WeavingTask WeavingTask;

    public void CheckForChanged()
    {
        var timeStamp = File.GetLastWriteTimeUtc(ProjectWeaversFinder.ConfigFilePath);
        DateTime dateTime;
        if (timeStamps.TryGetValue(ProjectWeaversFinder.ConfigFilePath, out dateTime))
        {
            if (dateTime != timeStamp)
            {
                Logger.LogWarning(string.Format("A rebuild is required to apply the changes from '{0}' to project '{1}'.", ProjectWeaversFinder.ConfigFilePath, WeavingTask.AssemblyPath));
            }
        }
        else
        {
            timeStamps[ProjectWeaversFinder.ConfigFilePath] = timeStamp;
        }
    }

    public void Flush()
    {
        timeStamps[ProjectWeaversFinder.ConfigFilePath] = File.GetLastWriteTimeUtc(ProjectWeaversFinder.ConfigFilePath);
    }
}